<html>
<head><title>Hausverbrauch</title></head>
<body>
    <form action="myurl" method="POST" name="myForm" id="myfrm">
        <p><label for="Wasser">Wasser:</label>
        <input type="number" name="wasser" id="nwasser"></p>

        <p><label for="Gas">Gas:</label>
        <input type="number" name="gas" id="ngas"></p>

        <p><label for="Strom">Strom zentral:</label>
        <input type="number" name="stromzentral" id="nstromzentral"></p>
        
        <p><label for="StromHerd">Strom Herd:</label>
        <input type="number" name="stromherd" id="nstromherd"></p>
        <p><label for="Stromgefrier">Strom Kühlschrank:</label>
        <input type="number" name="stromgefrier" id="nstromgefrier"></p>
        
        <input value="Submit" type="button" onclick="make_strom_json()">
    </form>
<div id="demo"></div>
<script>
function make_strom_json(){
	var d=new Date();
	var n=d.getTime();
<!--	document.getElementById("demo").innerHTML=n; -->
	var x=document.getElementById("myfrm")
	var text="";
	var i;
	for (i=0; i< x.length ; i++) {
		if(isNaN(x.elements[i].value) == false){
			if(x.elements[i].value > 0){
<!--				text += n + ":" + x.elements[i].name + ":" + x.elements[i].value + "<br>"; -->
				var json_out= JSON.stringify({time:n,device:'aither',sensor:'man',i2c:0,value:x.elements[i].value,varname:x.elements[i].name})
				text += json_out + "<br>"
				var xhr=new XMLHttpRequest();
				var url = "http://banana";
				xhr.open("POST",url,true);
				xhr.setRequestHeader("Content-Type","application/json");
				xhr.send(json_out)
			}
		}
	}
	document.getElementById("demo").innerHTML=text; 
}
</script>
</body>
</html>
